package com.ruoyi.web.controller.combat.apprisk;


import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.combat.service.apprisk.YueQuanService;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.combat.domain.apprisk.CombatAppTask;
import com.ruoyi.combat.service.apprisk.ICombatAppTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * app检测任务Controller
 *
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/combat/appTask")
public class CombatAppTaskController extends BaseController
{
    @Autowired
    private ICombatAppTaskService combatAppTaskService;
    @Autowired
    private YueQuanService yueQuanService;

    /**
     * 查询app检测任务列表
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatAppTask combatAppTask)
    {
        startPage();
        List<CombatAppTask> list = combatAppTaskService.selectCombatAppTaskList(combatAppTask);
        return getDataTable(list);
    }

    /**
     * 导出app检测任务列表
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:export')")
    @Log(title = "app检测任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatAppTask combatAppTask)
    {
        List<CombatAppTask> list = combatAppTaskService.selectCombatAppTaskList(combatAppTask);
        ExcelUtil<CombatAppTask> util = new ExcelUtil<CombatAppTask>(CombatAppTask.class);
        util.exportExcel(response, list, "app检测任务数据");
    }

    /**
     * 获取app检测任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(combatAppTaskService.selectCombatAppTaskById(id));
    }

    /**
     * 新增app检测任务
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:add')")
    @Log(title = "app检测任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatAppTask combatAppTask)
    {
        return toAjax(combatAppTaskService.insertCombatAppTask(combatAppTask));
    }

    /**
     * 修改app检测任务
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:edit')")
    @Log(title = "app检测任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatAppTask combatAppTask)
    {
        return toAjax(combatAppTaskService.updateCombatAppTask(combatAppTask));
    }

    /**
     * 删除app检测任务
     */
    @PreAuthorize("@ss.hasPermi('combat:appTask:remove')")
    @Log(title = "app检测任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(combatAppTaskService.deleteCombatAppTaskByIds(ids));
    }

    /**
     * app检测2
     */
    @Anonymous
    @PostMapping("/checkAppFuncation2")
    public AjaxResult checkAppFuncation2(@RequestBody Map map){
        if(map.get("apkPath")==null){
            return error("apk文件地址为空");
        }
        yueQuanService.checkAppFuncation2(String.valueOf(map.get("apkPath")));
        return success();
    }
}